﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Collections;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FUSE
{
    class MapValidator
    {
        //0 is unchecked
        //1 is checked
        //2 voronoi
        Matrix matrixDiagram;
        List<Vector2> pending;

        Hashtable galaxyComponents;


        public MapValidator(Hashtable galaxyComponents)
        {
            this.galaxyComponents = galaxyComponents;
        }


        public void factorGalaxyComponents()
        {
            foreach (GalaxyComponent item in this.galaxyComponents)
            {
                double radius = item.ComponentBounds.radius;
                double radianDegree = (2 * Math.PI) / (4 * radius);
                for (double currentRadian = 0; currentRadian < (2 * Math.PI); currentRadian += radianDegree)
                {
                    int xCoord = (int)(radius * Math.Cos(currentRadian));
                    int yCoord = (int)(radius * Math.Sin(currentRadian));

                    Vector2 temp = new Vector2();
                    temp.X = xCoord;
                    temp.Y = yCoord;

                    pending.Add(temp);
                }
            }
        }

        public void factorNeighbours()
        {
            Vector2 temp;
            List<Vector2> neighbours = new List<Vector2>();

            //main loop
            while (pending.Count > 0)
            {

                temp = pending.First();
                pending.RemoveAt(0);

                for (int x = ((int)(temp.X) - 1); x < ((int)temp.X) + 1; x++)
                {
                    for (int y = ((int)(temp.Y) - 1); y < ((int)temp.Y) + 1; y++)
                    {
                        if(x != (int)temp.X && y != (int)temp.Y)
                        {
                            temp = new Vector2();
                            temp.X = x;
                            temp.Y = y;
                            neighbours.Add(temp);
                        }
                    }

                }

                foreach (Vector2 nv in neighbours)
                {
                    //value corresponding to the valued raster grid of the game map
                    //int iTempVal = matrixDiagram.getValue((int)nv.X, (int)nv.Y);

                    matrixDiagram.setValue((int)nv.X, (int)nv.Y, matrixDiagram.getValue((int)nv.X, (int)nv.Y) + 1);
                    
                }


            }//main loop end


        }

    }
}
